﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Cotrobaie
{
    public partial class Categories : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String categID = Server.UrlDecode(Request.Params["categoryID"]);
            long CategoryID = 0;
            try { CategoryID = long.Parse(categID); }
            catch { Response.Redirect("~/Home.aspx"); }
            if (!Page.IsPostBack) Session["ProductsCurrPage"] = null;
            printinfo(CategoryID);
        }

        public void printinfo(long CategoryId)
        {

            // if nu exista produse in categorie
            // { Literal1.Text = "There are no products in this category."; pagesProducts.Visible = false;
            //else{
            
            PlaceHolder1.Controls.Clear();
            Table table = new Table();
            PlaceHolder1.Controls.Add(table);

            //for (int i = 0; i < ProduseInCategorie; i+=3){

                //first row - product image
                TableRow tr = new TableRow();

                TableCell tc = new TableCell();
                HyperLink hp = new HyperLink();
                hp.NavigateUrl = "product[i].linkSite";
                Image image = new Image();
                image.ImageUrl = "~/images/img.jpg";
                image.Width = 125;
                hp.Controls.Add(image);
                tc.Controls.Add(hp);
                tr.Cells.Add(tc);

                tc = new TableCell();
                tc.Width = 80;
                Label lab = new Label();
                lab.Text = "&nbsp;";
                tc.Controls.Add(lab);
                tr.Cells.Add(tc);

                tc = new TableCell();
                hp = new HyperLink();
                hp.NavigateUrl = "product[i+1].linkSite";
                image = new Image();
                image.ImageUrl = "~/images/img.jpg";
                image.Width = 125;
                hp.Controls.Add(image);
                tc.Controls.Add(hp);
                tr.Cells.Add(tc);

                tc = new TableCell();
                tc.Width = 80;
                lab = new Label();
                lab.Text = "&nbsp;";
                tc.Controls.Add(lab);
                tr.Cells.Add(tc);

                tc = new TableCell();
                hp = new HyperLink();
                hp.NavigateUrl = "product[i+2].linkSite";
                image = new Image();
                image.ImageUrl = "~/images/img.jpg";
                image.Width = 125;
                hp.Controls.Add(image);
                tc.Controls.Add(hp);
                tr.Cells.Add(tc);

                tc = new TableCell();
                tc.Width = 80;
                lab = new Label();
                lab.Text = "&nbsp;";
                tc.Controls.Add(lab);
                tr.Cells.Add(tc);

                table.Rows.Add(tr);

                //2-nd row - name of product

                tr = new TableRow();

                tc = new TableCell();
                tc.Style.Add("align","center");
                tc.Style.Add("padding", "5px");
                tc.Width = 100;
                hp = new HyperLink();
                hp.CssClass = "blgrlink";
                hp.NavigateUrl = "produs[i].linkSite";
                hp.Font.Bold = true;
                hp.Text = "produs[i].nume";
                tc.Controls.Add(hp);
                tr.Cells.Add(tc);

                tc = new TableCell();
                tc.Width = 80;
                lab = new Label();
                lab.Text = "&nbsp;";
                tc.Controls.Add(lab);
                tr.Cells.Add(tc);
                
                tc = new TableCell();
                tc.Style.Add("align", "center");
                tc.Style.Add("padding", "5px");
                tc.Width = 100;
                hp = new HyperLink();
                hp.CssClass = "blgrlink";
                hp.NavigateUrl = "produs[i+1].linkSite";
                hp.Font.Bold = true;
                hp.Text = "produs[i].nume";
                tc.Controls.Add(hp);
                tr.Cells.Add(tc);

                tc = new TableCell();
                tc.Width = 80;
                lab = new Label();
                lab.Text = "&nbsp;";
                tc.Controls.Add(lab);
                tr.Cells.Add(tc);

                tc = new TableCell();
                tc.Style.Add("align", "center");
                tc.Style.Add("padding", "5px");
                tc.Width = 100;
                hp = new HyperLink();
                hp.CssClass = "blgrlink";
                hp.NavigateUrl = "produs[i+2].linkSite";
                hp.Font.Bold = true;
                hp.Text = "produs[i].nume";
                tc.Controls.Add(hp);
                tr.Cells.Add(tc);
                table.Rows.Add(tr);


                //3-rd row - price of product
                tr = new TableRow();

                tc = new TableCell();
                tc.Style.Add("align", "center");
                tc.Style.Add("padding", "3px");
                tc.Style.Add("font-size", "12px");
                tc.Style.Add("color", "#ff5b02");
                lab = new Label();
                lab.Text = "produs[i].pret";
                tc.Controls.Add(lab);
                tr.Cells.Add(tc);

                tc = new TableCell();
                tc.Width = 80;
                lab = new Label();
                lab.Text = "&nbsp;";
                tc.Controls.Add(lab);
                tr.Cells.Add(tc);

                tc = new TableCell();
                tc.Style.Add("align", "center");
                tc.Style.Add("padding", "3px");
                tc.Style.Add("font-size", "12px");
                tc.Style.Add("color", "#ff5b02");
                lab = new Label();
                lab.Text = "produs[i+1].pret";
                tc.Controls.Add(lab);
                tr.Cells.Add(tc);

                tc = new TableCell();
                tc.Width = 80;
                lab = new Label();
                lab.Text = "&nbsp;";
                tc.Controls.Add(lab);
                tr.Cells.Add(tc);

                tc = new TableCell();
                tc.Style.Add("align", "center");
                tc.Style.Add("padding", "3px");
                tc.Style.Add("font-size", "12px");
                tc.Style.Add("color", "#ff5b02");
                lab = new Label();
                lab.Text = "produs[i+2].pret";
                tc.Controls.Add(lab);
                tr.Cells.Add(tc);

                tc = new TableCell();
                tc.Width = 80;
                lab = new Label();
                lab.Text = "&nbsp;";
                tc.Controls.Add(lab);
                tr.Cells.Add(tc);
                
                table.Rows.Add(tr);

                //empty row
                tr = new TableRow();
                tc = new TableCell();
                lab = new Label();
                lab.Text = "&nbsp;";
                tc.Controls.Add(lab);
                tr.Cells.Add(tc);
                table.Rows.Add(tr);

            //}
        }

        protected void ButtonPrevPage_Click(object sender, EventArgs e)
        {
            if (Session["ProductsCurrPage"] != null)
                Session["ProductsCurrPage"] = (int)Session["ProductsCurrPage"] - 1;
            else Session["ProductsCurrPage"] = 0;
            ButtonNextPage.Enabled = true;
            Page_Load(null, null);
            
        }

        protected void ButtonNextPage_Click(object sender, EventArgs e)
        {
            if (Session["ProductsCurrPage"] != null)
                Session["ProductsCurrPage"] = (int)Session["ProductsCurrPage"] + 1;
            else Session["ProductsCurrPage"] = 1;
            ButtonPrevPage.Enabled = true;
            Page_Load(null, null);
        }
    
    }
}